package com.xunlai.infra.permission.common.security;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import lombok.Getter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serial;
import java.io.Serializable;
import java.util.Collection;

/**
 * @author liang
 * @date 12/8/22 5:36 PM
 */
@Getter
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
public class TenantUser extends User implements Serializable {


    @Serial
    private static final long serialVersionUID = 4602381366537369203L;
    private final String tenant;

    private final String id;

    @JsonCreator
    public TenantUser(String tenant,String id,String username, String password, boolean enabled, boolean accountNonExpired,
                      boolean credentialsNonExpired, boolean accountNonLocked,
                      Collection<? extends GrantedAuthority> authorities) {
        super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
        this.tenant =tenant;
        this.id = id;
    }

    public TenantUser(String tenant, String id , UserDetails user){
        this(tenant,id,user.getUsername(), user.getPassword(),user.isEnabled(),user.isAccountNonExpired(),user.isCredentialsNonExpired(),user.isAccountNonLocked() ,user.getAuthorities());
    }


}
